/*=============================================================================
#     FileName: 前中序转后序.cpp
#         Desc: 清华高性能所机试题
#       Author: Ace
#        Email: goace@acm.org
#     HomePage: http://www.goace.co.cc
#      Version: 0.0.1
#   LastChange: 2011-08-29 21:21:31
#      History:
=============================================================================*/
#include  <iostream>
#include  <string>
#include  <unistd.h>
#include  <cstdlib>
using namespace std;

string a,b;

typedef struct node
{
	char c;
	node *left, *right;
}Node;

Node* transfer(int l1, int r1, int l2, int r2)
{
	
	Node *p = new Node;
	p->c = a[l1];
	if(l1 == r1)
	{
		if(a[l1] != b[l2])
		{
			cout << "NO ANSWER" << endl;
			exit(0);
		}
		p->left = p->right = NULL;
		return p;
	}
	int m = l2;
	while(b[m] != p->c && m != r2 + 1) m++;
	if(m == r2 + 1)
	{
		cout << "NO ANSWER" << endl;
		exit(0);
	}
	p->left = m-1-l2 > -1 ? 
		transfer(l1+1,l1+m-l2,l2,m-1) : NULL;
	p->right = r2-m-1 > -1 ? 
		transfer(l1+m-l2+1,r1,m+1,r2) : NULL;
	return p;
}

void dfs(Node *p)
{
	if(p->left != NULL)
		dfs(p->left);
	if(p->right != NULL)
		dfs(p->right);

	cout << p->c ;
}

int main(int argc, char *argv[])
{
	Node *head;
	cin >> a >> b;
	head = transfer(0,a.size()-1,0,b.size()-1);
	dfs(head);
	cout << endl;
}
